import java.io.*;
import java.util.Scanner;

public class IODemo8 {
    public static void main(String[] args) {
        //输入必要信息 源文件 目标文件名
        Scanner scanner=new Scanner(System.in);
        System.out.println("please input source file name :");
        String srcPath = scanner.next();
        System.out.println("please input destination file name :");
        String destPath = scanner.next();
        //验证
        File srcFile =new File(srcPath);
        File destFile=new File(destPath);

        if(!srcFile.isFile()){
            System.out.println("error");
            return;
        }
        if(!destFile.getParentFile().isDirectory()){
            System.out.println("error");
            return;
        }
        //复制操作
        try(InputStream inputStream=new FileInputStream(srcFile);
            OutputStream outputStream=new FileOutputStream(destFile)){
            while(true){
                byte[] buffer=new byte[1024];
                int n=inputStream.read(buffer);
                if(n == -1){
                    break;
                }
                outputStream.write(buffer,0,n);
            }
        }catch (IOException e){
            throw new RuntimeException(e);
        }
    }
}